import request from "./axios";

// 用户注册API
export function register(data) {
  return request({
    url: "/auth/register",
    method: "post",
    data,
  });
}

// 获取手机验证码
export function getPhoneVerificationCode(phone, usage = "login") {
  return request({
    url: "/auth/send-code",
    method: "post",
    data: { 
      type: "phone",
      target: phone,
      usage
    },
  });
}

// 获取邮箱验证码
export function getEmailVerificationCode(email, usage = "login") {
  return request({
    url: "/auth/send-code",
    method: "post",
    data: { 
      type: "email",
      target: email,
      usage
    },
  });
}

// 验证手机验证码
export function verifyPhoneCode(data) {
  return request({
    url: "/auth/verify-code/phone/verify",
    method: "post",
    data,
  });
}

// 验证邮箱验证码
export function verifyEmailCode(data) {
  return request({
    url: "/auth/verify-code/email/verify",
    method: "post",
    data,
  });
}

// 获取图形验证码（Base64格式）
export function getCaptcha() {
  return request({
    url: "/auth/captcha",
    method: "get",
  });
}

// 验证图形验证码
export function verifyCaptcha(data) {
  return request({
    url: "/auth/captcha/verify",
    method: "post",
    data,
  });
}

// 用户登录
export function login(data) {
  return request({
    url: "/auth/login",
    method: "post",
    data,
  });
}

// 退出登录
export function logout() {
  return request({
    url: "/auth/logout",
    method: "post",
  });
}

// 发送找回密码验证码
export function sendResetCode(data) {
  return request({
    url: "/auth/send-code",
    method: "post",
    data: {
      type: data.type,
      target: data.target,
      usage: "reset"
    }
  });
}

// 验证找回密码验证码
export function verifyResetCode(data) {
  return request({
    url: "/auth/verify-identity",
    method: "post",
    data: {
      type: data.type,
      target: data.target,
      verificationCode: data.code
    }
  });
}

// 重置密码
export function resetPassword(data) {
  return request({
    url: "/auth/reset-password",
    method: "post",
    data: {
      verifyToken: data.verifyToken,
      password: data.password
    }
  });
}
